#!/usr/bin/env python
#encoding : utf-8

class Response(object):
	def __init__(self, body='', status=200, headers=None):
		_headers = {}
		if headers:
			_headers = dict((key.lower(), value) for key, value in headers.items())
		_headers.setdefault('content-type', 'text/html')

		self.body = body
		self.status_code = status
		self._headers = _headers

	def set_header(self, header, content):
		self.__setitem__(header, content)

	def set_charset(self, charset):
		ct = self._headers['content-type'].lower().split(';', 1)[0]
		self._headers['content-type'] = '%s; charset=%s' % (ct, charset)

	@property
	def headers(self):
		headers = self._headers.items()
		return headers

	def __setitem__(self, key, value):
		self._headers[key.lower()] = value

	def __getitem__(self, key):
		return self._headers[key.lower()]

	def __contains__(self, key):
		return (key.lower() in self._headers)

	def has_key(self, key):
		return (key in self)

	def output(self):
		return self.body

if __name__ == '__main__':
	pass
